// pages/mainOperation/payment/payment.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: 0,
    orderPrice: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData(options)
  },
  /**
   * 支付
   */
  paymentTap() {
    var self = this;
    //根据授权码进行用户添加
    var url = app.apiBaseUrl + '/WxPay/WxMiniPay';

    app.httpRequest({
      url: url,
      showLoading: false,
      method: "GET",
      data: {
        orderId: self.data.orderId,
        openId: app.userInfo.ThirdUserID
      },
      success(res) {
        var rdata = res.data;
        wx.requestPayment({
          timeStamp: rdata.data.timeStamp,
          nonceStr: rdata.data.nonceStr,
          package: rdata.data.package,
          signType: rdata.data.signType,
          paySign: rdata.data.paySign,
          success: function(res) {
            wx.navigateBackMiniProgram({
              extraData: {
                orderId: self.data.orderId,
                result: 'success'
              },
              success(res) {
                // 返回成功
              }
            })

          },
          fail: function(res) {
            wx.navigateBackMiniProgram({
              extraData: {
                orderId: self.data.orderId,
                result: 'fail'
              },
              success(res) {
                // 返回成功
              }
            })
          }
        })
      },
      fail() {
        wx.navigateBackMiniProgram({
          extraData: {
            orderId: self.data.orderId,
            result: 'fail'
          },
          success(res) {
            // 返回成功
          }
        })
      }
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})